package web.blogsphere.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import web.blogsphere.mapper.BlogMapper;
import web.blogsphere.model.BlogInfo;

import java.util.List;

/**
 * @ClassName BlogService
 * @Description TODO
 * @Author ZJX
 * @Date 2024/9/3 22:47
 * @Version 1.0
 */
@Slf4j
@Service
public class BlogService {

    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> queryBlogList() {
        return blogMapper.selectAll();
    }

    public BlogInfo getBlogDetail(Integer blogId) {
        return blogMapper.selectById(blogId);
    }

    public Boolean insertBook(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.insertBlog(blogInfo);
            if (result==1){
                return true;
            }
        }catch (Exception e){
            log.error("添加图书失败, e:", e);
        }
        return false;
    }

    public Integer update(BlogInfo blogInfo) {
        return blogMapper.updateBlog(blogInfo);
    }

}
